// const host = 'http://localhost:9000'
const host = 'http://101.132.195.31'
const hostPage = 'http://jlwb.llbw.ltd/8088/page/index.html#/pages/index/index'
const orderPage = 'http://jlwb.llbw.ltd/8088/page/index.html#/pages/order/listToOrder'
const listPage = 'http://jlwb.llbw.ltd/8088/page/index.html#/pages/mine/myOrderList'

function doGet(path, refuse, reject) {
	uni.request({
		url: host + path,
		method: 'GET',
		success: (res) => {
			console.log('request-helper:\n' +
				host + path + '\n' +
				JSON.stringify(res));
			if (res.data.success) {
				refuse(res.data.data)
			} else {
				reject(res.data.msg)
			}
		},
		fail: (err) => {
			console.log('request-helper:\n' +
				host + path + '\n' +
				JSON.stringify(err));
			reject(err.msg)
		}
	});
}

function doPostForm(path, params, refuse, reject) {
	uni.request({
		url: host + path, //仅为示例，并非真实接口地址。
		data: params,
		method: 'POST',
		header: {
			'content-type': 'application/x-www-form-urlencoded;charset=utf-8'
		},
		success: (res) => {
			console.log('request-helper:\n' +
				host + path + '\n' +
				JSON.stringify(params) + '\n' +
				JSON.stringify(res));
			if (res.data.success) {
				refuse(res.data.data)
			} else {
				reject(res.data.msg)
			}
		},
		fail: (err) => {
			console.log(err);
			reject(err.msg)
		}
	});
}

function doPostJson(path, params, refuse, reject) {
	uni.request({
		url: host + path, //仅为示例，并非真实接口地址。
		data: params,
		method: 'POST',
		header: {
			'content-type': 'application/json;charset=utf-8'
		},
		success: (res) => {
			console.log('request-helper:\n' +
				host + path + '\n' +
				JSON.stringify(params) + '\n' +
				JSON.stringify(res));
			if (res.data.success) {
				refuse(res.data.data)
			} else {
				reject(res.data.msg)
			}
		},
		fail: (err) => {
			console.log('request-helper:\n' +
				host + path + '\n' +
				JSON.stringify(params) + '\n' +
				JSON.stringify(err));
			reject(err.msg)
		}
	});
}
export {
	orderPage,
	hostPage,
	listPage,
	doGet,
	doPostForm,
	doPostJson
}